<template>
	<div class="page-container">
	    <el-dialog :title="title" width="90%"    :visible.sync="coreStockDetailViewVisible"     :before-close="handleClose" >
		<div class="gk-layout-container">
		<div class="gk-layout-header">
			<!--工具栏-->
			<div class="toolbar" style="float:left;">
				<el-form :inline="true" :model="filters" :size="global.gSize">
					<el-form-item>
						<el-select v-model="filters.itemId" style="width: 175px;" clearable  filterable 	placeholder="物料">
							<el-option v-for="i in itemName" :key="i.id" :label="i.name"
								:value="i.id">
							</el-option>
						</el-select>
					</el-form-item>
					<el-form-item>
						<el-select v-model="filters.storeStatus" style="width: 175px;" clearable  filterable 	placeholder="物料">
							<el-option v-for="i in dicts.storeStatus" :key="i.value" :label="i.label"
								:value="i.value">
							</el-option>
						</el-select>
					</el-form-item>
					<el-form-item> <el-input v-model="filters.bName " placeholder="设备名称" /> </el-form-item>
					<el-form-item> <el-input v-model="filters.barCode " placeholder="设备编码" /> </el-form-item>
					<el-form-item>
						<kt-button icon="fa fa-search" :label="$t('action.search')" type="primary" @click="findPage(null)"  perms="core:stockDetail:show" />
						<kt-button icon="fa fa-search" label="盘库完成" type="primary" v-if="filters.pkId>0" @click="finshPk()"  perms="core:stockDetail:show" />
					</el-form-item>
				</el-form>
			</div>
			
		</div>
		<!--表格内容栏-->

		<div class="gk-layout-main" style="height:500px" >
			<my-table :data="pageResult.content"  :loading="loading"  >
				<el-table-column :label="$t('action.desc')" width="50" header-align="center" align="center">
					<template slot-scope="scope"> {{scope.$index+1}} </template>
				</el-table-column>
				<column prop="rLocId" label="位置"  />
				<column prop="itemId" label="物料名称"     :formatter="itemFilter"/> 
				<column prop="bName" label="设备名称"  />
				<column prop="barCode" label="设备编码"/>
		        <column prop="storeStatus" label="状态"    :formatter= "selectionFormat1" />

				
			</my-table>
		</div>
		<!--分页栏-->
		<div class="toolbar gk-layout-footer" style="padding:10px;">
			<el-pagination layout="total, prev, pager, next, jumper" @current-change="findPage"
				:current-page="pageRequest.pageNum" :page-size="pageRequest.pageSize" :total="pageResult.totalSize"
				style="float:right;">
			</el-pagination>
		</div>
		</div>
	</el-dialog>
</div>

</template>

<script> 
	import KtButton from "@/views/Core/KtButton"
	import MyTable from "@/views/Core/MyTable"
	import Column from "@/views/Core/Column"
	import { format } from "@/utils/datetime"
import {getItemName} from "@/utils/myUtil"
 

	export default {

		components: {
			KtButton,
			Column,
			MyTable
		},
		props: {
			filters: Object,
			coreStockDetailViewVisible: {
				type: Boolean
			},
			title:""
		},
		data() {
			return {
				
				loading: false,
				dicts: [],
				itemName:[],
			
				pageRequest: { pageNum: 1, pageSize: 7 },
				pageResult: {}, 
			}
		},
		methods: {
			 
			// 获取分页数据
			findPage: function (data) {
				data = data || 1
				this.filters.pageNum = data
				this.pageRequest.pageNum = data

				this.filters.pageSize = this.pageRequest.pageSize
				this.$api.coreStock.findDetailPage(this.filters).then((res) => {
					this.pageResult = res.data
				}).then(data != null ? data.callback : '')
			},

		finshPk: function () {
				
			var p={id:this.filters.pkId}
			
				this.$api.pk.finshPk(p).then((res) => {
					if (res.code == 200) {
						this.$message({ message:  res.msg, type: 'success' })
									
					} else {
						this.$message({ message:  res.msg, type: 'error' })
					}
				})
			},
		  	selectionFormat1: function (row, column, cellValue, index) {
				let propt = column.property;
				let val = row[propt];
				let dict = this.dicts["storeStatus"];
				for (let i = 0; i < dict.length; i++) {
					if (dict[i].value == val) {
						return dict[i].label;
					}
				}
				return row[propt]
      		},
			itemFilter: function (row, column, cellValue, index) {
									return getItemName(cellValue,this.itemName)
			},
		 
			getItemName:function (id){
		       var items=this.itemName;
				for(var j=0;j<items.length;j++){
					if(items[j].id==id){
						return items[j].name;
					}
				}
				return id;
			},
		
		   handleClose: function () {
			this.$emit('coreStockDetailListHidden', {})
		},
 
			
		},
		
		mounted() {
			
		   this.dicts=this.$store.state.dict.dicts;
			this.itemName=this.$store.state.dict.item;
		
		},
		watch:{

			coreStockDetailViewVisible(n,o){

				if(n===true){
	this.findPage();
					
				}
				
			}


		}
	}
</script>

<style scoped>

</style>